<template>
    <div style="height: 100%; width: 100%; position: relative">
        <div class="pagetop">
            <div class="search-title">
                <table class="table1style" style="width: 100%; white-space: nowrap">
                    <col style="width: 4%" />
                    <col style="width: 14%" />
                    <col style="width: 1%" />
                    <col style="width: 14%" />
                    <col style="width: 5%" />
                    <col style="width: 12%" />
                    <col style="width: 5%" />
                    <col style="width: 12%" />
                    <col style="width: 4%" />
                    <col style="width: 12%" />
                    <col style="width: 5%" />
                    <col style="width: 12%" />
                    <tr>
                        <td align="right" style="width: 80px">交接时间</td>
                        <td>
                            <el-date-picker v-model="createtimefrom" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"> </el-date-picker>
                        </td>
                        <td>至</td>
                        <td>
                            <el-date-picker v-model="createtimeto" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"> </el-date-picker>
                        </td>
                        <td align="right">送出组</td>
                        <td>
                            <rm-ddl-common @change="labgroupchange1" datatype="labgroup" dataname="检验工作组" v-model="txtsendgroup" width="100%"></rm-ddl-common>
                        </td>
                        <td align="right">送出部门</td>
                        <td>
                            <rm-ddl-common @change="labdeptchange1" datatype="dept" dataname="送出部门" v-model="txtsendlabdept" width="100%"></rm-ddl-common>
                        </td>
                        <td align="right">送出人</td>
                        <td>
                            <rm-ddl-common @change="userchange1" datatype="userinfo" dataname="送出人" v-model="txtsenduser" width="100%"></rm-ddl-common>
                        </td>
                        <td align="right">传递类型</td>
                        <td>
                            <el-select v-model="txttrantype" @change="InitPage" filterable clearable style="width: 100%">
                                <el-option v-for="(item, index) in $opt.TransType" :key="index" :label="item.label" :value="item.value"></el-option>
                            </el-select>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">交接单号</td>
                        <td colspan="3">
                            <el-input v-model="txtpackbarcode" width="100%" @keyup.enter.native="InitPage"></el-input>
                        </td>
                        <td align="right">接收组</td>
                        <td>
                            <rm-ddl-common @change="labgroupchange2" datatype="labgroup" dataname="检验工作组" v-model="txtreceivegroup" width="100%"></rm-ddl-common>
                        </td>
                        <td align="right">接收部门</td>
                        <td>
                            <rm-ddl-common @change="labdeptchange2" datatype="dept" dataname="接收部门" v-model="txtreceivelabdept" width="100%"></rm-ddl-common>
                        </td>
                        <td align="right">接收人</td>
                        <td>
                            <rm-ddl-common @change="userchange2" datatype="userinfo" dataname="接收人" v-model="txtreceiveuser" width="100%"></rm-ddl-common>
                        </td>
                        <td align="right">标本条码</td>
                        <td>
                            <el-input v-model="txtbarcode" style="width: 100%" @keyup.enter.native="InitPage"></el-input>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="top-deal">
                <el-button @click="InitPage" icon="el-icon-search" type="primary">查询</el-button>
                <el-button @click="btnSort" icon="el-icon-sort">排序</el-button>
                <el-button @click="btnClear" icon="el-icon-close">清除</el-button>
                <el-button @click="btnPrint($event)" icon="el-icon-printer">打印清单</el-button>
                <el-button @click="btnExport" icon="el-icon-upload2">导出</el-button>
                <!-- <el-button @click="btnShowReqGroup" icon="el-icon-s-order">显示分单类别数量</el-button> -->
                <!--这个功能暂时不做-->
                <el-button @click="btnPrintPackBarcode" icon="el-icon-printer">打印包条码</el-button>
            </div>
        </div>
        <div class="pagecenter">
            <div class="middle-center">
                <rm-layout-right splitcolor="white" movingcolor="#0000ff" :splitwidth="5" :fixsize="500">
                    <template v-slot:fix>
                        <rm-layout-bottom splitcolor="white" :splitwidth="5" :canDrag="false" :fixsize="60">
                            <div style="height: 100%; width: 100%; background-color: #ddccbb" v-loading="pageinitloading" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)">
                                <vxe-table :data.sync="req_transdetail" :loading="loading" :cell-class-name="cellClassName" :keyboard-config="keyConfig" :select-config="selectConfig" :sort-config="{ trigger: 'cell' }" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" border fit height="auto" header-align="center" highlight-current-row highlight-hover-row class="mytablestyle" highlight-hover-column ref="xTable2" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe>
                                    <vxe-table-column field="req_groupna" title="分单类别" width="106" header-align="center">
                                        <template v-slot="{ row }">
                                            <div v-bind:style="{ background: $pub.ColorChange(row.tube_color), color: $pub.colorConvert(row.tube_color) }">{{ row.req_groupna }}</div>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column field="specimen_name" title="标本类型 " width="74" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="req_deptname" title="申请科室" width="104" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="req_bedno" title="床号" width="54" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="pat_name" title="姓名" width="50" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="pat_sexname" title="性别" width="45" header-align="center" align="center"></vxe-table-column>
                                    <vxe-table-column field="req_statname" title="申请状态" width="78" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="barcode" title="条码号" width="100" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="emer_flag" title="加急" width="45" header-align="center" align="center">
                                        <template v-slot="{ row }">
                                            <div style="color: red">{{ row.emer_flag == "0" ? "" : "急" }}</div>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column field="sample_items" title="申请项目(简称，部分) " width="203" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="rcvscan_dt" title="单个扫描确认时间 " width="130" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                                    <vxe-table-column field="reject_reason" title="退回原因" width="205" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="base_amount" title="应收金额" width="70" header-align="center" align="right"></vxe-table-column>
                                    <vxe-table-column field="req_wardname" title="所属病区" width="105" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="pat_no" title="病人号" width="105" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="req_docname" title="申请医生" width="75" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="pat_typename" title="病人类型" width="77" header-align="center" align="center"></vxe-table-column>
                                    <vxe-table-column field="create_username" title="创建人" width="50" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="reject_username" title="退回人" width="50" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="reject_dt" title="退回时间 " width="90" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                                    <vxe-table-column field="print_dt" title="打印/执行日期" width="120" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                                    <vxe-table-column field="print_username" title="打印/执行人" width="78" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="print_count" title="打印次数" width="78" header-align="center" align="center"></vxe-table-column>
                                    <vxe-table-column field="sampled_dt" title="采样时间" width="121" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                                    <vxe-table-column field="sampled_username" title="采样人" width="93" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="req_dt" title="申请日期" width="120" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                                    <vxe-table-column field="pat_diag" title="临床诊断" width="133" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="pat_agestr" title="年龄字串" width="70" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="pat_id" title="病人唯一号" width="97" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="inp_date" title="入院日期 " width="90" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                                    <vxe-table-column field="send_dt" title="护工交接时间 " width="126" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                                    <vxe-table-column field="send_username" title="送出护工 " width="93" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="recieve_dt" title="检验科接收时间 " width="120" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                                    <vxe-table-column field="recieve_username" title="检验科接收用户 " width="123" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="charge_dt" title="计价时间" width="120" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                                    <vxe-table-column field="charge_username" title="计价人" width="54" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="amount" title="实收总金额" width="80" header-align="center" align="right"></vxe-table-column>
                                    <vxe-table-column field="charge_flag" title="收费标志" width="70" header-align="center" :edit-render="{ name: 'select', options: $opt.chargeOption }"></vxe-table-column>
                                    <vxe-table-column field="test_dt" title="上机时间" width="120" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                                    <vxe-table-column field="test_username" title="上机人" width="50" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="report_dt" title="报告时间" width="120" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                                    <vxe-table-column field="report_username" title="检验医生姓名" width="92" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="rechk_username" title="核对医生姓名" width="92" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="alter_flag" title="警告" width="45" header-align="center">
                                        <template v-slot="{ row }">
                                            <div>{{ row.alter_flag == "0" ? "" : row.alter_flag == "1" ? "警" : "" }}</div>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column field="saleman" title="所属销售人" width="89" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="pat_cardno" title="就诊卡号" width="129" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="req_comm" title="医生备注" width="197" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="pat_birth" title="病人生日" width="90" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                                    <vxe-table-column field="pat_ageyear" title="年龄岁数" width="80" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="inp_id" title="住院标识" width="70" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="pat_diag_icd" title="诊断的ICD10编码" width="121" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="pat_address" title="病人联系地址" width="145" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="pat_nation" title="国家/民族" width="90" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="pat_idcardno" title="身份证号护照号" width="142" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="pat_phone" title="联系电话" width="84" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="charge_typename" title="收费类型" width="82" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="perform_deptname" title="执行科室" width="83" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="original_reqno" title="原始单号" width="80" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="secrecy" title="加密标志" width="60" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="other_stat" title="备用标志" width="60" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="cancel_dt" title="作废时间" width="120" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                                    <vxe-table-column field="cancel_username" title="作废用户 " width="75" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="reject_count" title="退回次数" width="60" header-align="center" align="right"></vxe-table-column>
                                    <vxe-table-column field="sample_detail" title="标本备注说明" width="101" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="req_reason" title="送检目的" width="107" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="multi_seq" title="多条码序号" width="100" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="req_groupid" title="分单类别" width="100" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="report_id" title="报告单ID" width="81" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="report_user" title="检验医生" width="81" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="rechk_user" title="核对医生" width="80" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="recieve1_dt" title="工作组接收时间 " width="120" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                                    <vxe-table-column field="recieve1_username" title="工作组接收用户" width="109" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="inlib_status" title="入库状态" width="70" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="library_id" title="所在库位ID" width="82" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="reqtype" title="业务类别" width="60" header-align="center" :edit-render="{ name: 'select', options: $opt.reqtype }"> </vxe-table-column>
                                    <vxe-table-column field="pat_height" title="身高" width="65" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="weight" title="体重" width="71" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="abo_bldtype" title="ABO血型" width="90" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="rh_bldtype" title="RH血型" width="94" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="hospcodename" title="送检医院" width="133" header-align="center"></vxe-table-column>
                                    <vxe-table-column field="recieve_host" title="检验科接收电脑" width="120" header-align="center"></vxe-table-column>
                                </vxe-table>
                                <div class="table-bottom">
<div style="font-size: 17px; padding-left: 3px; background-color: #fff; overflow: auto; text-align: center">
                                            <span style="font-weight: bold; margin-left: 18px; color: red">未收：{{ unRvcSum }}个</span>
                                        </div>
                                </div>
                            </div>
                            <template v-slot:fix>
                                <div style="border: 1px solid #ccc; height: 60px" v-loading="pageinitloading" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)">
                                    <span v-for="(item, index) in SumInfo" :key="index"
                                        ><span style="font-weight: bold; margin-left: 18px" :style="{ background: $pub.ColorChange(item.content.tubecolor), color: $pub.colorConvert(item.content.tubecolor) }">{{ item.content.req_groupna }}：{{ item.content.sum }}</span>
                                    </span>
                                </div>
                            </template>
                        </rm-layout-bottom>
                    </template>
                    <div style="height: 100%; width: 100%; background-color: #ddccbb">
                        <div style="height: 100%; width: 100%; background-color: #ddccbb">
                            <vxe-table :data.sync="req_trans" :loading="loading" :keyboard-config="keyConfig" :select-config="selectConfig" :sort-config="{ trigger: 'cell' }" :edit-config="{ trigger: 'click', mode: 'cell', activeMethod: activeMethod, showStatus: true, showIcon: false }" @current-change="currentChangeEvent" border fit height="auto" header-align="center" highlight-current-row highlight-hover-row class="mytablestyle" highlight-hover-column ref="xTable1" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe>
                                <!-- <vxe-table-column type="index" title="NO." width="45" align="center"></vxe-table-column> -->
                                <vxe-table-column field="status" title="状态" width="60"> </vxe-table-column>
                                <vxe-table-column field="packagebarcode" title="传送条码" width="90" align="center"> </vxe-table-column>
                                <vxe-table-column field="transtype" title="传递类型" width="80"> </vxe-table-column>
                                <vxe-table-column field="labgroupid" title="送出组" width="70"> </vxe-table-column>
                                <vxe-table-column field="senddept" title="送出部门" width="75"> </vxe-table-column>
                                <vxe-table-column field="senduser" title="送出人" width="50" align="center"> </vxe-table-column>
                                <vxe-table-column field="samplecount" title="标本数" width="60" align="center" header-align="center"> </vxe-table-column>
                                <vxe-table-column field="transtime" title="交接时间" width="130" align="center"> </vxe-table-column>
                                <vxe-table-column field="recieveuser" title="接收者" width="50" align="center"> </vxe-table-column>
                                <vxe-table-column field="reclabgroupid" title="接收组" width="75"> </vxe-table-column>
                                <vxe-table-column field="recievedept" title="接收部门科室" width="95"> </vxe-table-column>
                                <vxe-table-column field="createuser" title="创建者" width="50" align="center"> </vxe-table-column>
                                <vxe-table-column field="createtime" title="创建时间" width="135" align="center"> </vxe-table-column>
                                <vxe-table-column field="comments" title="备注" width="140"> </vxe-table-column>>
                            </vxe-table>
                            <div class="table-bottom">
  <div style="font-size: 17px; padding-left: 3px; background-color: #fff; overflow: auto; text-align: center">
                                        <span style="font-weight: bold; margin-left: 18px; color: red">标本总数：{{ sum }}个</span>
                                    </div>
                            </div>
                        </div>
                    </div>
                </rm-layout-right>
            </div>
        </div>

        <!--显示分单类别数量弹窗-->
        <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="分单类别统计" :visible.sync="dialogShowReqGroup" width="420px">
            <div style="height: 400px">
                <div class="pagecenter-p">
                    <div class="middle-center-p">
                        <vxe-table height="auto" :data.sync="list" :select-config="selectConfig" :sort-config="{ trigger: 'cell' }" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" border fit header-align="center" highlight-current-row highlight-hover-row highlight-hover-column ref="pxTable" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe>
                            <vxe-table-column type="index" title="NO." width="45" align="center"></vxe-table-column>
                            <vxe-table-column field="req_groupna" title="分单类别" width="206" header-align="center">
                                <template v-slot="{ row }">
                                    <div v-bind:style="{ background: $pub.ColorChange(row.tube_color), color: $pub.colorConvert(row.tube_color) }" style="height: 20px; width: 120px">{{ row.req_groupna }}</div>
                                </template>
                            </vxe-table-column>
                            <vxe-table-column field="samplecnt" title="数量" width="106"> </vxe-table-column>
                        </vxe-table>
                    </div>
                </div>
            </div>
        </el-dialog>

        <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="导出" :visible.sync="dialogExport">
            <span>选择是则导出结果信息，选择否则导出结果明细信息，选择取消则取消本次导出！</span>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="exportfun(1)">是</el-button>
                <el-button type="primary" @click="exportfun(2)">否</el-button>
                <el-button @click="dialogExport = false">取 消</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
    name: "LIS227",
    data() {
        return {
            createtimefrom: this.$pub.InitDateTime2(0).datefrom,
            createtimeto: this.$pub.InitDateTime2(0).dateto,
            txtsendgroup: "",
            txtsenduser: "",
            txttrantype: "",
            txtpackbarcode: "",
            txtreceivegroup: "",
            txtreceiveuser: "",
            txtbarcode: "",
            txtsendlabdept: "",
            txtreceivelabdept: "",
            keyConfig: {
                isDel: true,
                isTab: true,
                isEdit: true,
                isArrow: true,
            },
            keyLocalConfig: {
                isArrow: true,
            },
            selectConfig: { tigger: "row" },
            req_trans: [],
            req_transdetail: [],
            loading: false,
            dialogShowReqGroup: false,
            dialogExport: false,
            SumInfo: [],
            tableColumnResult: [],
            tableColumnDetail: [],
            sortArr: [],
            packbarStyleid: "5015",
            CircStyleid: "5008",
            pageinitloading: false,
            sortColumn: [],
            sendgroupname: "",
            receivegroupname: "",
            sendusername: "",
            receiveusername: "",
            sendlabdeptname: "",
            receivelabdeptname: "",
            exportTableColLen: 0,
            selrow: {},
        };
    },
    created() {
        this.InitPage(); //初始化主列表
        this.InitOption(); //初始化下拉框的数据
    },
    computed: {
        sum() {
            return XEUtils.sum(this.req_trans, "samplecount");
        },
        unRvcSum() {
            let data = this.req_transdetail.filter((item) => Number(item.req_stat) < 4);
            return data.length;
        },
        list() {
            try {
                if (this.req_trans.length > 0) {
                    let data = this.group(this.req_trans, function (item) {
                        return item.req_groupna + "," + item.tube_color;
                    });
                    return data;
                }
            } catch (e) {
                this.$alert("出错：" + e);
            }
        },
    },
    mounted() {},
    updated() {},
    methods: {
        group(list, f) {
            //分组函数
            const groups = {};
            list.forEach(function (re) {
                const group = f(re);
                groups[group] = groups[group] || [];
                groups[group].push(re);
            });
            return Object.keys(groups).map(function (group) {
                let groupLabel = group.split(","); //根据“，”切割成数组（可自定义）
                return {
                    req_groupna: groupLabel[0], //分单类别
                    tube_color: groupLabel[1], //颜色
                    samplecnt: groups[group].length, //数量
                };
            });
        },
        InitOption() {
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS227",
                    method: "post",
                    data: {
                        action: "getoptions",
                    },
                })
                .then((res) => {
                    if(!!res.packbarStyleid){
                        this.packbarStyleid = res.packbarStyleid;
                    }
                    this.CircStyleid = res.CircStyleid;
                })
                .catch((err) => {
                    this.$alert(err);
                });
        },
        InitPage() {
            this.loading = true;
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS227",
                    method: "post",
                    data: {
                        action: "InitPage",
                        createtimefrom: this.createtimefrom,
                        createtimeto: this.createtimeto,
                        txtsendgroup: this.txtsendgroup,
                        txtsenduser: this.txtsenduser,
                        txttrantype: this.txttrantype,
                        txtpackbarcode: this.txtpackbarcode,
                        txtreceivegroup: this.txtreceivegroup,
                        txtreceiveuser: this.txtreceiveuser,
                        txtbarcode: this.txtbarcode,
                        txtsendlabdept: this.txtsendlabdept,
                        txtreceivelabdept: this.txtreceivelabdept,
                        sortArr: this.sortArr,
                    },
                })
                .then((res) => {
                    this.req_trans = res.data;
                    if (res.data.length > 0) {
                        this.$refs.xTable1.setCurrentRow(res.data[0]);
                        this.querydetail(res.data[0]);
                    } else {
                        this.req_trans = [];
                        this.req_transdetail = [];
                        this.selrow = {};
                    }
                    this.loading = false;
                })
                .catch((err) => {
                    this.loading = false;
                });
        },
        async querydetail(row) {
            try {
                this.selrow = row;
                this.pageinitloading = true;
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS227",
                    method: "post",
                    data: {
                        action: "querydetail",
                        packagebarcode: row.packagebarcode,
                    },
                });
                this.req_transdetail = res.data;
                this.SumInfo = [];
                if (res.data.length > 0) {
                    for (const item of res.data) {
                        await this.reqgroupnaInfo(item);
                    }
                }
                this.pageinitloading = false;
            } catch (e) {
                this.pageinitloading = false;
                this.$alert(e);
            }
        },
        rowClassName({ row, rowIndex }) {
            return this.$pub.getreqstatclass(row.req_stat);
        },
        cellClassName({ column, row }) {
            if (column.property == "req_groupna") {
                return "";
            } else {
                return this.$pub.getreqstatclass(row.req_stat);
            }
        },
        activeMethod() {
            return false;
        },
        currentChangeEvent({ row }) {
            if (this.pageinitloading) {
                this.$refs.xTable1.setCurrentRow(this.selrow);
            } else {
                this.querydetail(row);
            }
        },
        btnSort() {
            if (this.sortColumn.length == 0) {
                let columns = this.$refs.xTable1.getColumns();
                columns.forEach((item) => {
                    this.sortColumn.push({ title: item.title, field: item.property });
                });
            }
            this.$rmsort(
                { tableColumn: this.sortColumn, sortArr: this.sortArr },
                {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }
            )
                .then((res) => {
                    this.sortArr = res.data;
                    this.InitPage();
                })
                .catch(() => {});
        },
        btnClear() {
            this.InitDate();
            this.txtsendgroup = "";
            this.txtsenduser = "";
            this.txttrantype = "";
            this.txtpackbarcode = "";
            this.txtreceivegroup = "";
            this.txtreceiveuser = "";
            this.txtbarcode = "";
            this.txtsendlabdept = "";
            this.txtreceivelabdept = "";
            this.req_trans = [];
            this.req_transdetail = [];
            this.SumInfo = [];
        },
        async btnPrint(e) {
            if (e.shiftKey) {
                //调整
                let sql = "select top 1 1 as 条数,2 as 交接批号,* from req_master_all_name";
                this.$pub.printlistbill(this, sql, "3", this.CircStyleid, "流转清单样式", "");
            } else {
                let item = this.$refs.xTable1.getCurrentRow();
                if (item) {
                    const rLoading = this.$pub.openLoading(this, "正在打印交接清单……");
                    let data = await this.getSonBarcodes(item.packagebarcode);
                    if (data.sum > 0) {
                        var barcodes = data.barcodes.replace(/,/g,"','");
                        let sql = "select '" + data.sum + "' as 条数,'" + item.packagebarcode + "' as 交接批号,* from req_master_all_name where 条码号 in ('" + barcodes + "')";
                        this.$pub.printlistbill(this, sql, "1", this.CircStyleid, "流转清单样式", "");
                    }
                    rLoading.close();
                } else {
                    this.$alert("请选中要打印的数据！");
                }
            }
        },
        async getSonBarcodes(packbarcode) {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS222",
                    method: "post",
                    data: {
                        action: "getSonBarcodes",
                        packbarcode: packbarcode,
                    },
                });
                return res;
            } catch (e) {
                this.$alert(e);
            }
        },
        exportfun(index) {
            if (index == 1) {
                let filtertxt = this.getExportFilter();
                let data = this.getExportData("1");
                this.$pub.exportTableExcelWithData(data, this.exportTableColLen, "LIS227标本流转记录查询result.xlsx", filtertxt);
            } else {
                if(this.selrow) {
                    let filtertxt = "传送条码:" + this.selrow.packagebarcode + "; ";
                    let data = this.getExportData("2");
                    this.$pub.exportTableExcelWithData(data, this.exportTableColLen, "LIS227标本流转记录查询detail.xlsx", filtertxt);
                } else {
                    this.$alert("请选择要导出的记录");
                }
            }
            this.dialogExport = false;
        },
        // 获取当前导出文件的所有查询条件
        getExportFilter() {
            let filtertxt = "";
            let createtimetxt = "";
            if(this.createtimefrom) createtimetxt += XEUtils.toDateString(this.createtimefrom, "yyyy-MM-dd HH:mm:ss");
            if(this.createtimeto) createtimetxt += "至" + XEUtils.toDateString(this.createtimeto, "yyyy-MM-dd HH:mm:ss");
            if(createtimetxt) filtertxt += "交接时间:" + createtimetxt + "; ";
            if(this.txtsendgroup) filtertxt += "送出组:" + this.sendgroupname + "; ";
            if(this.txtsendlabdept) filtertxt += "送出部门:" + this.sendlabdeptname + "; ";
            if(this.txtsenduser) filtertxt += "送出人:" + this.sendusername + "; ";
            if(this.txttrantype) filtertxt += "传递类型:" + this.getOptionName(this.$opt.TransType.filter((item) =>  this.txttrantype == item.value)) + "; ";
            if(this.txtpackbarcode) filtertxt += "交接单号:" + this.txtpackbarcode + "; ";
            if(this.txtreceivegroup) filtertxt += "接收组:" + this.receivegroupname + "; ";
            if(this.txtreceivelabdept) filtertxt += "接收部门:" + this.receivelabdeptname + "; ";
            if(this.txtreceiveuser) filtertxt += "接收人:" + this.receiveusername + "; ";
            if(this.txtbarcode) filtertxt += "标本条码:" + this.txtbarcode + "; ";
            return filtertxt;
        },
        getOptionName(option) {
            if (option && option.length > 0) {
                let optionname = "";
                option.forEach((item) => {
                    if(item.hasOwnProperty("display")) {
                        optionname += item.display + ",";
                    } else {
                        optionname += item.label + ",";
                    }
                });
                return optionname.substring(0, optionname.length - 1);
            } else {
                return "";
            }
        },
        getExportData(index) {
            let datas = [];
            let columns = [];
            if (index == "1") {
                datas = this.req_trans;
                if (this.tableColumnResult.length == 0) {
                    let columns = this.$refs.xTable1.getColumns();
                    columns.forEach((item) => {
                        this.tableColumnResult.push({ title: item.title, field: item.property });
                    });
                }
                this.exportTableColLen = this.tableColumnResult.length;
                columns = this.tableColumnResult.filter((item) => item.field);
            } else {
                datas = this.req_transdetail;
                if (this.tableColumnDetail.length == 0) {
                    let columns = this.$refs.xTable2.getColumns();
                    columns.forEach((item) => {
                        this.tableColumnDetail.push({ title: item.title, field: item.property });
                    });
                }
                this.exportTableColLen = this.tableColumnDetail.length;
                columns = this.tableColumnDetail.filter((item) => item.field);
            }
            let headers = [columns.map((item) => item.title)];
            return headers.concat(
                datas.map((row) => {
                    return columns.map((column) => {
                        return row[column.field];
                    });
                })
            );
        },
        btnExport() {
            this.dialogExport = true;
        },
        btnShowReqGroup() {
            this.dialogShowReqGroup = true;
        },
        async btnPrintPackBarcode() {
            let kdata = this.$refs.xTable1.getCurrentRow();
            if (!!kdata.packagebarcode) {
                let data = await this.getSonBarcodes(kdata.packagebarcode); //this.master.length;
                if (data.sum > 0) {
                    const rLoading = this.$pub.openLoading(this, "正在打印包条码……");
                    var packagebarcode = kdata.packagebarcode;
                    let sql= "select SampleCount as 标本数量, SendUser as 送出人, CONVERT(varchar,GETDATE(),120) as 打印时间,  PackageBarcode as 包条码号,  dc_dept.deptname as 接收部门, RecLabGroupID as 接收工作组, bb.deptname as 送出部门,cc.allcomcount as 单采标本数,cc.allmixcount as 混检标本数,u.username as 创建者, comments as 备注,'' as 采样点 from Req_Trans left join dc_dept on Req_Trans.RecieveDept = dc_dept.deptno left join dc_dept bb on Req_Trans.senddept = bb.deptno left join secsysuser u on Req_Trans.createuser = u.userno left join (select '" + packagebarcode.trim() + "' as packagebrc,count(*) as allcount, sum(mixcount) as allmixcount, (count(*) - sum(mixcount)) as allcomcount from (select a.packagebarcode, (case when isnull(b.mixbarcode, '') = '' then 0 else 1 end) as mixcount from req_transdetail as a left join req_mixsample b on a.barcode = b.mixbarcode where PackageBarcode = '" + packagebarcode.trim() + "') c) cc on Req_Trans.packagebarcode = cc.packagebrc where Req_Trans.PackageBarcode = '" + packagebarcode.trim() + "'";
                    this.$pub.printlistbill(this, sql, "1", this.packbarStyleid, "打印包条码", "");
                    rLoading.close();
                }
            } else {
                this.$alert("没有获取到条码，无法打印！");
                return false;
            }
        },
        labgroupchange1(code, name) {
            this.txtsendgroup = code;
            this.sendgroupname = name;
            this.InitPage();
        },
        labgroupchange2(code, name) {
            this.txtreceivegroup = code;
            this.receivegroupname = name;
            this.InitPage();
        },
        userchange1(code, name) {
            this.txtsenduser = code;
            this.sendusername = name;
            this.InitPage();
        },
        userchange2(code, name) {
            this.txtreceiveuser = code;
            this.receiveusername = name;
            this.InitPage();
        },
        labdeptchange1(code, name) {
            this.txtsendlabdept = code;
            this.sendlabdeptname = name;
            this.InitPage();
        },
        labdeptchange2(code, name) {
            this.txtreceivelabdept = code;
            this.receivelabdeptname = name;
            this.InitPage();
        },
        async reqgroupnaInfo(resmaster) {
            //当前列表中没有这条数据则加一
            let data = this.req_transdetail;
            //this.master.filter(item => item.barcode == resmaster.barcode);
            if (data.length > 0) {
                //当前主列表没有就加入统计
                if (this.SumInfo.length > 0) {
                    let existfalge = false;
                    try {
                        this.SumInfo.forEach((item) => {
                            if (item.reqgroupid === resmaster.req_groupid) {
                                item.content.sum++;
                                existfalge = true;
                                throw ERROR();
                            }
                        });
                    } catch (e) {}
                    if (!existfalge) {
                        let reqgroupid = resmaster.req_groupid;
                        let tempjson = { req_groupna: resmaster.req_groupna, sum: 1, tubecolor: resmaster.tube_color };
                        this.SumInfo.push({ reqgroupid: reqgroupid, content: tempjson });
                    }
                } else {
                    let reqgroupid = resmaster.req_groupid;
                    let tempjson = { req_groupna: resmaster.req_groupna, sum: 1, tubecolor: resmaster.tube_color };
                    this.SumInfo.push({ reqgroupid: reqgroupid, content: tempjson });
                }
            }
        },
    },
};
</Script>

<style scoped>
.pagetop {
    width: 100%;
    height: 95px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 99;
}

.pagecenter {
    position: absolute;
    top: 100px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}

.middle-center {
    position: absolute;
    height: 100%;
    left: 0px;
    right: 0px;
    overflow: auto;
}

.pagecenter-p {
    top: 0px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}

.middle-center-p {
    height: 380px;
    left: 0px;
    right: 0px;
    overflow: auto;
    margin-top: 5px;
}

table {
    font-size: 12px;
    border-collapse: separate;
    border-spacing: 5px;
}

.table1style tr td {
    /*  padding: 0px 5px 0px 2px;*/
}

/deep/ .el-button.is-disabled {
    border: 0px;
    color: grey;
    background-color: #e6e6e6;
    font-weight: normal;
}
.search-title {
    margin: 0 5px 0 20px;
    font-size: 12px;
    top: 0px;
    position: absolute;
}
.top-deal {
    right: 5px;
    position: absolute;
    top: 65px;
    display: flex;
    align-items: center;
}
/deep/ tr.vxe-body--row.row-modify {
    color: blue;
}
/deep/ tr.vxe-body--row.row-new {
    color: #cc6600;
}
.pagecenter/deep/.mytablestyle tr td div .el-input__inner {
    /* border: 1px solid rgba(255, 254, 254, 0) !important;
    background-color: rgba(255, 254, 254, 0) !important;*/
}

.table-bottom {
    position: absolute;
    left: 0px;
    bottom: 0%;
    z-index: 1;
    overflow: hidden;
    width: 100%;
}
</style>